<template>
  <div>
    1234
    <button type="button" @click="handleClick">Click</button>
  </div>
</template> 

<script setup>
let controller = null;
const fetchData = () => {
  if (controller) {
    controller.abort("取消上一次请求");
  }
  controller = new AbortController();
  return new Promise((resolve, reject) => {
    fetch("/api/getName", { signal: controller.signal })
      .then((res) => res.json())
      .then((res) => {
        resolve(res);
      });
  });
};

const handleClick = () => {
  fetchData()
    .then((data) => {
      console.log(data);
    })
    .catch((err) => {
      alert(err);
    });
};
</script>

<style>
div {
  color: red;
}
</style>


<script>
</script> 